import time
import datetime
import threading

class Interval:
    
    def __init__(self, callback, t=0):
        
        self.startTime = 0
        self.timeInterval = t
        self.callback = callback
        self.__down = False
    
    
    def w (self):
        self.startTime = int(time.time())

        while not self.__down:
            self.__down = self.isDown()
        
        self.callback()
        
    def isDown(self):
        now = int(time.time())
        print(now - self.startTime)
        return (now - self.startTime) >= self.timeInterval

    def start(self):
        
        self.startTime = int(time.time())
        self.__down = self.isDown()
        
        if self.__down:
            self.callback()
        
    def init(self):
        self.__down = False
    
    def stop(self):
        self.down = True